package org.zkoss.zktc.core.widget;

import org.openqa.selenium.WebElement;
import org.zkoss.zktc.core.widget.impl.SelectWidgetImpl;
import org.zkoss.zktc.core.widget.impl.WidgetDriverImpl;

public class Widgets {

	public static SelectWidget toSelectWidget(Widget widget){
		WidgetDriverImpl driver = (WidgetDriverImpl)widget.getDriver();
		WebElement we = widget.getDom();
		String className = widget.getClassName();
		String mold = (String)widget.getAttribute("mold");
		if("zul.sel.Select".equals(className)){
			if("select".equals(mold)){
				return new SelectWidgetImpl(driver, widget.getGadgetId(), true);
			}
		}else if("zul.wgt.Selectbox".equals(className)){
			return new SelectWidgetImpl(driver, widget.getGadgetId(), true);
		}
		throw new RuntimeException("Could not wrap widget "+className+", mold="+mold+" to SelectWidget");
	}	
}
